export default {
    data() {
        return {

        }
    },
	
}
export const loginUrl = {
	data() {
	    return {
			loginUrlList:['pages/member/member',
			'pages/service/addplan',
			'pages/service/comparison',
			'pages/service/comparisonresults',
			'pages/service/customized',
			'pages/service/datascreening',
			'pages/service/family',
			'pages/service/plan',
			'pages/service/setgoals',
			'pages/service/trend',
			'pages/service/viewplan',
			'pages/service/weightpad',
			'pages/service/weightpadlist',
			'pages/member/question',
			'pages/member/questions',
			'pages/member/setting',
			'pages/member/user',
			'pages/member/userinfo',
			'pages/order/index',
			'pages/order/orderlist',
			'pages/service/takephoto',
			'pages/service/list',
			'pages/service/exercise'
			],
	    }
	},
	methods: {
		isLogin(url){
			if (!url) {
				return
			}
			let newUrl = url
			// 过滤首位的 /
			if (url[0] === '/') {
				newUrl = url.substring(1)
			}
			const pathname = newUrl.split('?')[0]
			
			if (this.loginUrlList.includes(pathname)) {
				if(this.vuex_token){
					return true
				}else{
					uni.$u.toast('请您先登录')
					uni.$u.sleep(500).then(() => {
						uni.navigateTo({
							url:'/pages/login/login'
						})
					})
					return false	
				}
				
			}else{
				return true
			}
		}
	}
}
export const tools = {
	filters: {

	},
	computed: {

	},
	methods: {
		//富文本的回调
		navigate(e) {
			if (e.href && e.href.indexOf('http') == -1) { //不完整的链接						
				//详情				
				let res = e.href.match(new RegExp("(a)|(\\d+)", 'g'));
				if (res.length == 2) {
					this.$u.route('/pages/article/detail', {
						id: res[1]
					});
					return;
				}
				// #ifdef MP
				this.$util.uniCopy({
					content: this.vuex_config.upload.cdnurl + e.href,
					success: () => {
						this.$u.toast('链接已复制,请在浏览器中打开')
					}
				})
				// #endif
				// #ifndef MP				
				window.open(this.vuex_config.upload.cdnurl + e.href);
				// #endif
			}
		},
		//预览图片
		lookImage(index) {
			uni.previewImage({
				current: index,
				urls: this.imagesList,
				longPressActions: {
					itemList: ['发送给朋友', '保存图片', '收藏'],
					success: function(data) {
						console.log(data)
					},
					fail: function(err) {
						console.log(err.errMsg);
					}
				}
			});
		},
		//复制url
		copyUrl(url = '') {
			this.$util.uniCopy({
				content: url || window.location.href,
				success: () => {
					this.$u.toast('复制成功，请去粘贴发送给好友吧');
				},
				error: () => {
					console.log('复制失败！')
				}
			})
		},
		//cdnurl
		cdnurl(url) {
			if (!/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/.test(url)) {
				return this.vuex_config.upload.cdnurl + url;
			}
			return url;
		},
		//页面跳转
		goPage(path, auth) {
			if (path == 'out') {
				this.$u.vuex('vuex_token', '');
				this.$u.vuex('vuex_user', {});
				this.$u.vuex('vuex_openid', '');
				return;
			}
			if (auth && !this.vuex_token) {
				this.$u.route('/pages/login/mobilelogin');
				return;
			}
			let type = 'navigateTo';

			// #ifdef MP-WEIXIN
			//优化当pages超过5个时的处理
			let pages = getCurrentPages();
			type = pages.length >= 4 ? 'redirectTo' : type;
			// #endif

			uni.$u.route({
				url: path,
				type: type,
				complete(e) {
					console.log(e, path)
				}
			})
		}
	}
}


